package fr.yan.com;
import java.io.BufferedWriter;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.File;
import java.util.ArrayList;
import java.util.List;

/**
 * @author Yann
 * Project X
 * 31 oct. 2012
 */

public class FichiersTexte {
	
	/**
	 * ?.
	 */
	public FichiersTexte() {
		
	}

	
 //public void  Fich(String[] tab, int max, String dossier) throws IOExceptionhikhjnik {	
	public void  Fich(List<String> tab, int max, String dossier, int nbLigne) throws IOException {	
	   
	      PrintWriter out = null;
	      int i = 0;
	      int j = 0;
		 try {
			 System.out.println(max);
			File dos = new File(dossier);
			dos.mkdir();
			
			for (j = 0; j <= C.c20; j++) {
				int nblettres = 0;
			// for (i = 0; i < tab.length; i++) {
				for (i = 0; i < nbLigne; i++) {
				  // if (String.valueOf(tab[i]).length() == j) {
					if (tab.get(i).length() == j) {
					   if (nblettres == 0) {
						   out = new PrintWriter(new BufferedWriter(new FileWriter(dossier + "/"  + j + "_lettres.txt")));
						   nblettres = 1;
					   }
					  // if (tab[i] != null) {
					   if (tab.get(i) != null) {
						 //out.write(tab[i] + "\n");
						   out.write(tab.get(i) + "\n");
						}
							
				    }
				}
			 
			 
		 
			 if (nblettres == 1) {
				 out.close();
			 }
				
			 // System.out.println(j);

			}
	     
		} catch (FileNotFoundException e) {
			
			e.printStackTrace();
			
		} finally { 
			if (out != null) {
				out.close();
			}
	    }
	}
}
	

